home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectShow / Editing / XTLTestVB / frmMain.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  19.0 KB  |  426 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "XtlTest"
  5.    ClientHeight    =   1140
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4470
  9.    Icon            =   "frmMain.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   1140
  14.    ScaleWidth      =   4470
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin VB.CheckBox ChkDynamic 
  17.       Caption         =   "Dynamic Sources"
  18.       Height          =   255
  19.       Left            =   960
  20.       TabIndex        =   4
  21.       Top             =   720
  22.       Value           =   1  'Checked
  23.       Width           =   1935
  24.    End
  25.    Begin VB.CommandButton CmdReplay 
  26.       Caption         =   "&Replay"
  27.       Enabled         =   0   'False
  28.       Height          =   375
  29.       Left            =   120
  30.       TabIndex        =   2
  31.       Top             =   720
  32.       Width           =   735
  33.    End
  34.    Begin VB.Timer tmrTimer 
  35.       Interval        =   1000
  36.       Left            =   3900
  37.       Top             =   675
  38.    End
  39.    Begin VB.PictureBox picDropBox 
  40.       BackColor       =   &H00FFFFFF&
  41.       Height          =   495
  42.       Left            =   120
  43.       OLEDropMode     =   1  'Manual
  44.       ScaleHeight     =   435
  45.       ScaleWidth      =   4155
  46.       TabIndex        =   0
  47.       Top             =   120
  48.       Width           =   4215
  49.       Begin VB.Label lblDragAndDrop 
  50.          BackStyle       =   0  'Transparent
  51.          Caption         =   "Drag and Drop an XTL file in the box."
  52.          Enabled         =   0   'False
  53.          Height          =   255
  54.          Left            =   720
  55.          TabIndex        =   3
  56.          Top             =   120
  57.          Width           =   2775
  58.       End
  59.       Begin VB.Label lbPlaying 
  60.          Alignment       =   2  'Center
  61.          BackStyle       =   0  'Transparent
  62.          Caption         =   "P L A Y I N G"
  63.          Enabled         =   0   'False
  64.          BeginProperty Font 
  65.             Name            =   "Comic Sans MS"
  66.             Size            =   9.75
  67.             Charset         =   0
  68.             Weight          =   700
  69.             Underline       =   0   'False
  70.             Italic          =   0   'False
  71.             Strikethrough   =   0   'False
  72.          EndProperty
  73.          Height          =   255
  74.          Left            =   720
  75.          TabIndex        =   1
  76.          Top             =   120
  77.          Visible         =   0   'False
  78.          Width           =   2655
  79.       End
  80.    End
  81. Attribute VB_Name = "frmMain"
  82. Attribute VB_GlobalNameSpace = False
  83. Attribute VB_Creatable = False
  84. Attribute VB_PredeclaredId = True
  85. Attribute VB_Exposed = False
  86. '*******************************************************************************
  87. '*       This is a part of the Microsoft DXSDK Code Samples.
  88. '*       Copyright (C) 1999-2001 Microsoft Corporation.
  89. '*       All rights reserved.
  90. '*       This source code is only intended as a supplement to
  91. '*       Microsoft Development Tools and/or SDK documentation.
  92. '*       See these sources for detailed information regarding the
  93. '*       Microsoft samples programs.
  94. '*******************************************************************************
  95. Option Explicit
  96. Option Base 0
  97. Option Compare Text
  98. Private m_objTimeline As AMTimeline
  99. Private m_objMediaEvent As IMediaEvent
  100. Private m_objRenderEngine As RenderEngine
  101. ' **************************************************************************************************************************************
  102. ' * PRIVATE INTERFACE- FORM EVENTS
  103.             ' ******************************************************************************************************************************
  104.             ' * procedure name: Form_Terminate
  105.             ' * procedure description:  Occurs when all references to an instance of a Form, MDIForm, or class are removed from memory.
  106.             ' *
  107.             ' ******************************************************************************************************************************
  108.             Private Sub Form_Terminate()
  109.             On Local Error GoTo ErrLine
  110.             
  111.             'ensure timer disabled
  112.             tmrTimer.Enabled = False
  113.             
  114.             'clean-up & dereference
  115.             Call ClearTimeline(m_objTimeline)
  116.             If Not m_objMediaEvent Is Nothing Then Set m_objMediaEvent = Nothing
  117.             If Not m_objRenderEngine Is Nothing Then Set m_objRenderEngine = Nothing
  118.             Exit Sub
  119.             
  120. ErrLine:
  121.             Err.Clear
  122.             Exit Sub
  123.             End Sub
  124.             
  125.             
  126.             
  127. ' **************************************************************************************************************************************
  128. ' * PRIVATE INTERFACE- CONTROL EVENTS
  129.             ' ******************************************************************************************************************************
  130.             ' * procedure name: ChkDynamic_Click
  131.             ' * procedure description: Occurs when the 'Dynamic' checkbox is elected by the user.
  132.             ' *
  133.             ' ******************************************************************************************************************************
  134.             Private Sub ChkDynamic_Click()
  135.             On Local Error GoTo ErrLine
  136.             Call SetDynamicLevel(m_objRenderEngine)
  137.             Exit Sub
  138.             
  139. ErrLine:
  140.             Err.Clear
  141.             Exit Sub
  142.             End Sub
  143.             
  144.             
  145.             ' ******************************************************************************************************************************
  146.             ' * procedure name: CmdReplay_Click
  147.             ' * procedure description: Occurs when the 'Replay' command button is clicked by the user.
  148.             ' *
  149.             ' ******************************************************************************************************************************
  150.             Private Sub CmdReplay_Click()
  151.             Dim objVideoWindow As IVideoWindow
  152.             Dim objMediaPosition As IMediaPosition
  153.             Dim objFilterGraphManager As FilgraphManager
  154.             On Local Error GoTo ErrLine
  155.             
  156.             ' if there's no render engine, there's nothing to replay
  157.             If m_objRenderEngine Is Nothing Then Exit Sub
  158.             
  159.             ' ask for the graph, so we can control it
  160.             Call m_objRenderEngine.GetFilterGraph(objFilterGraphManager)
  161.             
  162.             'if we have a valid instance of a filtergraph, run the graph
  163.             If Not objFilterGraphManager Is Nothing Then
  164.                Call objFilterGraphManager.Stop
  165.                Set objMediaPosition = objFilterGraphManager
  166.                If Not objMediaPosition Is Nothing Then objMediaPosition.CurrentPosition = 0
  167.                Call objFilterGraphManager.Run
  168.                Set m_objMediaEvent = objFilterGraphManager
  169.             End If
  170.             
  171.             'set the UI state
  172.             lbPlaying.Visible = True
  173.             tmrTimer.Enabled = True
  174.             lblDragAndDrop.Visible = False
  175.             picDropBox.BackColor = &HFF
  176.             
  177.             If Not objFilterGraphManager Is Nothing Then
  178.                'derive an interface for the video window
  179.                Set objVideoWindow = objFilterGraphManager
  180.                      If Not objVideoWindow Is Nothing Then
  181.                         objVideoWindow.Visible = True
  182.                         objVideoWindow.Left = 0
  183.                         objVideoWindow.Top = 0
  184.                      End If
  185.             End If
  186.             
  187.             'clean-up & dereference
  188.             If Not objVideoWindow Is Nothing Then Set objVideoWindow = Nothing
  189.             If Not objMediaPosition Is Nothing Then Set objMediaPosition = Nothing
  190.             If Not objFilterGraphManager Is Nothing Then Set objFilterGraphManager = Nothing
  191.             Exit Sub
  192.             
  193. ErrLine:
  194.             Err.Clear
  195.             Exit Sub
  196.             End Sub
  197.             ' ******************************************************************************************************************************
  198.             ' * procedure name: picDropBox_OLEDragDrop
  199.             ' * procedure description:  Occurs when data is dropped onto the control via an OLE drag/drop operation,
  200.             ' *                                       and OLEDropMode is set to manual.
  201.             ' *                                       Here we dropped an XTL file on the timeline, so create a timeline, a render engine,
  202.             ' *                                       an XML parser, and load them all up
  203.             ' ******************************************************************************************************************************
  204.             Private Sub picDropBox_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  205.             Dim nCount As Long
  206.             Dim bstrFileName As String
  207.             Dim objXMLParser As New Xml2Dex
  208.             On Local Error GoTo ErrLine
  209.             
  210.             'ensure that among the files being dragged is an xtl file..
  211.             For nCount = 1 To Data.Files.Count
  212.                   If Len(Data.Files.Item(nCount)) > 4 Then
  213.                      If LCase(Right(Data.Files.Item(nCount), 4)) = ".xtl" Then
  214.                         Effect = vbDropEffectCopy
  215.                         bstrFileName = Data.Files(nCount)
  216.                         Exit For
  217.                      End If
  218.                   End If
  219.             Next
  220.             'otherwise do not allow the drag operation to continue
  221.             If bstrFileName = vbNullString Then
  222.                Effect = vbDropEffectNone: Exit Sub
  223.             End If
  224.             
  225.             'ensure timer is disabled
  226.             tmrTimer.Enabled = False
  227.             
  228.             'clean-up & dereference
  229.             Call ClearTimeline(m_objTimeline)
  230.             If Not m_objMediaEvent Is Nothing Then Set m_objMediaEvent = Nothing
  231.             If Not m_objRenderEngine Is Nothing Then Set m_objRenderEngine = Nothing
  232.             
  233.             
  234.             'reinstantiate the timeline & render engine
  235.             Set m_objTimeline = New AMTimeline
  236.             Set m_objRenderEngine = New RenderEngine
  237.             
  238.             'Set the dynamic level on or off
  239.             Call SetDynamicLevel(m_objRenderEngine)
  240.             
  241.             'read in the file
  242.             Call objXMLParser.ReadXMLFile(m_objTimeline, bstrFileName)
  243.             
  244.             ' make sure all the sources exist where they should
  245.             ' the 27 is a combination of flags from qedit.idl (c/c++ stuff)
  246.             m_objTimeline.ValidateSourceNames 27, Nothing, vbNull
  247.             
  248.             'set the timeline
  249.             m_objRenderEngine.SetTimelineObject m_objTimeline
  250.             
  251.             'connect the front
  252.             m_objRenderEngine.ConnectFrontEnd
  253.             
  254.             'render the output pins (e.g. 'backend')
  255.             m_objRenderEngine.RenderOutputPins
  256.             
  257.             'set the caption on the form & enable replay there after
  258.             frmMain.CmdReplay.Enabled = True
  259.             frmMain.Caption = "XtlTest -" + bstrFileName
  260.             
  261.             'replay the timeline
  262.             Call CmdReplay_Click
  263.             
  264.             'clean-up & dereference
  265.             If Not objXMLParser Is Nothing Then Set objXMLParser = Nothing
  266.             Exit Sub
  267.             
  268. ErrLine:
  269.             Err.Clear
  270.             Exit Sub
  271.             End Sub
  272.             ' ******************************************************************************************************************************
  273.             ' * procedure name: picDropBox_OLEDragOver
  274.             ' * procedure description:  Occurs when the mouse is moved over the control during an OLE drag/drop operation, if its OLEDropMode property is set to manual.
  275.             ' *
  276.             ' ******************************************************************************************************************************
  277.             Private Sub picDropBox_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  278.             Dim nCount As Long
  279.             On Local Error GoTo ErrLine
  280.             
  281.             'ensure that among the files being dragged is an xtl file..
  282.             For nCount = 1 To Data.Files.Count
  283.                   If Len(Data.Files.Item(nCount)) > 4 Then
  284.                      If LCase(Right(Data.Files.Item(nCount), 4)) = ".xtl" Then
  285.                         Effect = vbDropEffectCopy
  286.                         Exit Sub
  287.                      End If
  288.                   End If
  289.             Next
  290.             
  291.             'otherwise do not allow the drag operation to continue
  292.             Effect = vbDropEffectNone
  293.             Exit Sub
  294.             
  295. ErrLine:
  296.             Err.Clear
  297.             Exit Sub
  298.             End Sub
  299.             ' ******************************************************************************************************************************
  300.             ' * procedure name: picDropBox_OLEGiveFeedback
  301.             ' * procedure description:  Occurs at the source control of an OLE drag/drop operation when the mouse cursor needs to be changed.
  302.             ' *
  303.             ' ******************************************************************************************************************************
  304.             Private Sub picDropBox_OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)
  305.             On Local Error GoTo ErrLine
  306.             
  307.             'setup the ole drop effect
  308.             Effect = vbDropEffectCopy
  309.             Exit Sub
  310.             
  311. ErrLine:
  312.             Err.Clear
  313.             Exit Sub
  314.             End Sub
  315.             
  316.             ' ******************************************************************************************************************************
  317.             ' * procedure name: tmrTimer_Timer
  318.             ' * procedure description:  Occurs when a preset interval for a Timer control has elapsed.
  319.             ' *
  320.             ' ******************************************************************************************************************************
  321.             Private Sub tmrTimer_Timer()
  322.             Dim nResultant As Long
  323.             Dim objVideoWindow As IVideoWindow
  324.             Dim objMediaPosition As IMediaPosition
  325.             Dim objFilterGraphManager As FilgraphManager
  326.             On Local Error GoTo ErrLine
  327.             
  328.             
  329.             If Not m_objMediaEvent Is Nothing Then
  330.                'wait 10 ms to see if it's running or not
  331.                Call m_objMediaEvent.WaitForCompletion(10, nResultant)
  332.               
  333.                'derive an instance of the video window
  334.                Set objVideoWindow = m_objMediaEvent
  335.                
  336.                If objVideoWindow.Visible = False Then
  337.                    'the user closed the video window, hault playback
  338.                     If Not m_objRenderEngine Is Nothing Then
  339.                        Call m_objRenderEngine.GetFilterGraph(objFilterGraphManager)
  340.                     End If
  341.                     'the end of the media has been reached
  342.                     lbPlaying.Visible = False
  343.                     lblDragAndDrop.Visible = True
  344.                     objVideoWindow.Visible = False
  345.                     picDropBox.BackColor = &HFFFFFF
  346.                     
  347.                     'if we have a valid instance of a filtergraph, run the graph
  348.                     If Not objFilterGraphManager Is Nothing Then
  349.                        Call objFilterGraphManager.Stop
  350.                        Set objMediaPosition = objFilterGraphManager
  351.                        If Not objMediaPosition Is Nothing Then objMediaPosition.CurrentPosition = 0
  352.                        Set m_objMediaEvent = objFilterGraphManager
  353.                     End If
  354.             
  355.                ElseIf nResultant <> 1 Then ' 1 = EC_COMPLETE
  356.                   'the end of the media has not been reached, exit
  357.                   Exit Sub
  358.                Else
  359.                   'the end of the media has been reached
  360.                   lbPlaying.Visible = False
  361.                   lblDragAndDrop.Visible = True
  362.                   objVideoWindow.Visible = False
  363.                   picDropBox.BackColor = &HFFFFFF
  364.                End If
  365.             End If
  366.             
  367.             'clean-up & dereference
  368.             If Not objVideoWindow Is Nothing Then Set objVideoWindow = Nothing
  369.             If Not objMediaPosition Is Nothing Then Set objMediaPosition = Nothing
  370.             If Not objFilterGraphManager Is Nothing Then Set objFilterGraphManager = Nothing
  371.             Exit Sub
  372.             
  373. ErrLine:
  374.             Err.Clear
  375.             Exit Sub
  376.             End Sub
  377.             
  378.             
  379.             
  380.             
  381. ' **************************************************************************************************************************************
  382. ' * PRIVATE INTERFACE- PROCEDURES
  383.             ' ******************************************************************************************************************************
  384.             ' * procedure name: ClearTimeline
  385.             ' * procedure description:  Clear everything out so we can start over or exit
  386.             ' *
  387.             ' ******************************************************************************************************************************
  388.             Private Sub ClearTimeline(objTimeline As AMTimeline)
  389.             On Local Error GoTo ErrLine
  390.             
  391.             ' we need to call this manually, since groups
  392.             ' themselves can have a circular reference back to the timeline
  393.             If Not objTimeline Is Nothing Then
  394.                Call objTimeline.ClearAllGroups: Set objTimeline = Nothing
  395.             End If
  396.             Exit Sub
  397.             
  398. ErrLine:
  399.             Err.Clear
  400.             Exit Sub
  401.             End Sub
  402.             
  403.             
  404.             
  405.             ' ******************************************************************************************************************************
  406.             ' * procedure name: SetDynamicLevel
  407.             ' * procedure description:  we can either make the sources load before the project runs, or let them load when needed.
  408.             ' *
  409.             ' ******************************************************************************************************************************
  410.             Private Sub SetDynamicLevel(objRenderEngine As RenderEngine)
  411.             On Local Error GoTo ErrLine
  412.             
  413.             'proceed to set the dynamic reconnection level on the given render engine
  414.             If Not objRenderEngine Is Nothing Then
  415.                If ChkDynamic.Value Then
  416.                    objRenderEngine.SetDynamicReconnectLevel 1
  417.                Else: objRenderEngine.SetDynamicReconnectLevel 0
  418.                End If
  419.             End If
  420.             Exit Sub
  421.             
  422. ErrLine:
  423.             Err.Clear
  424.             Exit Sub
  425.             End Sub
  426.